package com.ruoyi.web.controller.wq;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.AppConfigService;
import com.ruoyi.system.domain.vo.SysConfigVO;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.wq.domain.vo.WqTopicVO;
import com.ruoyi.wq.service.IWqTopicService;
import com.ruoyi.wq.service.IWqTopicUserService;

/**
 * 话题Controller
 * 
 * @author ruoyi
 * @date 2022-06-17
 */
@RestController
@RequestMapping("/wq/topic")
public class WqTopicController extends BaseController {
	
    @Autowired
    private IWqTopicService wqTopicService;
    
    @Autowired
    private IWqTopicUserService wqTopicUserService;
    
    @Autowired
    private ISysUserService sysUserService;
    
    @Autowired
    private AppConfigService appConfigService;
    
    /**
     * 获取话题详细信息
     */
    @GetMapping(value = "/getDetail")
    public AjaxResult getDetail(String id){
        return AjaxResult.success(wqTopicService.getDetail(id));
    }
    
    /**
     * 查询话题列表
     */
    @GetMapping("/getList")
    public AjaxResult getList() {
        List<WqTopicVO> list = wqTopicService.getList();
        return AjaxResult.success(list);
    }
    
    /**
     * 关注话题
     */
    @GetMapping(value = "/fans")
    public AjaxResult fans(String id){
        return AjaxResult.success(wqTopicService.fans(id));
    }
    
    /**
     * 获取热门话题
     */
    @Anonymous
    @GetMapping(value = "/getHotTopic")
    public AjaxResult getHotTopic(WqTopicVO vo){
    	Boolean flag = false;
    	if(StringUtils.isNotBlank(vo.getAppId())){
    		if("wx2b5596fc2c4454d4".equals(vo.getAppId())){
    			flag = false;
    		}else{
    			SysConfigVO config = new SysConfigVO();
            	config.setAppId(vo.getAppId());
            	config.setUserId(vo.getUserId());
            	String value = appConfigService.getChatValue(config);
            	if("0".equals(value)){
            		// 审核期间
            		if(vo.getUserId() == null || vo.getUserId().intValue() == 0){
            			flag = true;
            		}else{
            			SysUser user = sysUserService.getById(vo.getUserId());
            			if("0".equals(user.getIsAuth())){
            				flag = true;
            			}
            		}
            	}
    		}
    	}
        return AjaxResult.success(wqTopicService.getHotTopicList(flag));
    }
    
    /**
     * 获取更多话题
     */
    @GetMapping(value = "/getMoreTopic")
    public AjaxResult getMoreTopic(){
    	AjaxResult ajax = AjaxResult.success();
        ajax.put("topicList", wqTopicService.getTopicList());
        ajax.put("fansTopicList", wqTopicUserService.getFansTopicList());
        return ajax;
    }
    
}
